/* rqsetopn.p - REQUISITION SET OPEN AND APPROVAL STATUS INDICATORS           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.5 $                                                         */
/*V8:ConvertMode=NoConvert                                                    */
/* Revision: 8.6    LAST MODIFIED BY: 05/05/97  By: B. Gates          *J1Q2*  */
/* Revision: 8.5    LAST MODIFIED BY: 09/09/99  BY: *J39R* Reetu Kapoor       */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00 BY: *N0KP* myb                    */
/* $Revision: 1.5 $    BY: Sandeep P.            DATE: 09/21/01  ECO: *M1LT*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}

define input parameter p_req_nbr like rqm_mstr.rqm_nbr no-undo.

{rqconst.i}
define variable found_open       as   logical     no-undo.
define variable qty_open         like rqd_req_qty no-undo.
define variable requm            like rqd_um      no-undo.
define variable found_approved   as   logical     no-undo.
define variable found_unapproved as   logical     no-undo.
define variable found_oot        as   logical     no-undo.

find rqm_mstr
   where rqm_nbr = p_req_nbr
exclusive-lock.

for each rqd_det
   exclusive-lock
   where rqd_nbr = rqm_nbr:

   if rqd_status = ""
   then do:

      {gprun.i ""rqoqty.p""
         "(input  no,
           input  rqd_site,
           input  rqd_nbr,
           input  rqd_line,
           output qty_open,
           output requm)"}

      rqd_open = qty_open <> 0.
      if rqd_open
      then
         found_open = true.
   end. /* IF rqd_status = "" */
   else
      rqd_open = false.

   /** CLOSING THE DETAIL LINE STATUS IF NO OPEN QUANTITY PRESENT **/
   if  rqd_open   = false
   and rqd_status = ""
   then
      rqd_status = "c".

   /*REMEMBER LINE APPROVAL STATUS*/

   if rqd_status = ""
   then do:
      if rqd_aprv_stat = APPROVAL_STATUS_UNAPPROVED
      then
         found_unapproved = true.
      else
      if rqd_aprv_stat = APPROVAL_STATUS_APPROVED
      then
         found_approved = true.
      else
      if rqd_aprv_stat = APPROVAL_STATUS_OOT
      then
         found_oot = true.
   end. /* IF rqd_status = "" */

end. /* FOR EACH rqd_det */

rqm_open = found_open.

if  rqm_open   = false
and rqm_status = ""
then
   rqm_status = "c".

/** REQ HEADER STATUS SHOULD BE BLANK IF ANY ONE LINE  **/
/** IS STILL OPEN                                      **/

if  rqm_status = "c"
and rqm_open   = true
then
   rqm_status = "".

/*SET HEADER APPROVAL STATUS*/
if rqm_status = ""
then do:
   if found_unapproved
   then
      rqm_aprv_stat = APPROVAL_STATUS_UNAPPROVED.
   else
   if found_oot
   then
      rqm_aprv_stat = APPROVAL_STATUS_OOT.
   else
   if found_approved
   then
      rqm_aprv_stat = APPROVAL_STATUS_APPROVED.
   else
      rqm_aprv_stat = APPROVAL_STATUS_UNAPPROVED.
end. /* IF rqm_status = "" */
